package com.zlx.guguanjia.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zlx.guguanjia.entity.WorkOrder;
import com.zlx.guguanjia.mapper.DetailMapper;
import com.zlx.guguanjia.mapper.TransferMapper;
import com.zlx.guguanjia.mapper.WorkOrderMapper;
import com.zlx.guguanjia.service.WorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @Author 周罗校
 * @Description
 * @ClassName WorkOrderServiceImpl
 * @date 2020.10.28 12:18:25
 * 该版权归周罗校所有，最终解释权以官方为准
 */

@Service
@Transactional
public class WorkOrderServiceImpl extends BaseServiceImpl<WorkOrder,Long> implements WorkOrderService {
    @Autowired
    private WorkOrderMapper workOrderMapper;

    @Autowired
    private DetailMapper detailMapper;
    @Autowired
    private TransferMapper transferMapper;

    @Override
    public PageInfo<WorkOrder> selectPage(int start, int pageSize, Map<String, Object> map) {
        PageHelper.startPage(start,pageSize);
        return new PageInfo<>(workOrderMapper.selectPage(map));
    }

    /**
     * 根据工单id查询工单详情：
     * 1.根据工单id查询工单、用户、企业信息
     * 2.根据工单id查询详单、大小分类信息
     * 3.根据工单id查询转运记录、转运人信息，倒序排列
     */
    @Override
    public Map<String,Object> selectById(long id){
        Map<String, Object> work = workOrderMapper.selectById(id);
        List<Map<String, Object>> details = detailMapper.selectById(id);
        List<Map<String, Object>> transfers = transferMapper.selectById(id);
        work.put("details",details);
        work.put("transfers",transfers);
        return work;
    }
}
